Ext.define('KitchenSink.view.examples.forms.Contact', {
    extend: 'KitchenSink.view.examples.Example',
    requires: [
        'Ext.form.FieldContainer',
        'Ext.form.Panel',
        'Ext.form.field.Text',
        'Ext.form.field.TextArea',
        'Ext.layout.container.Anchor',
        'Ext.layout.container.HBox'
    ],

    items: [{
        xtype: 'form',
        
        id:'adduseraccount',
        title: '添加账号',
        frame: true,
        
        height: 230,
        width: 400,
        layout: 'column',
        border: true,
        bodyStyle:'padding:5px;',
        fieldDefaults: {
        	layout: 'form',
            labelAlign: 'right',
            labelWidth:85,
            labelStyle: 'font-weight:bold'
        },
        defaults: {
            margins: '10 10 10 10',
            columnWidth:1
        },
        items: [
        {
        	xtype: 'combo',
        	store:new Ext.data.Store({
        		 autoload:true,
            	 proxy: new Ext.data.HttpProxy({  
                     //这里是参数可以顺便写,这个数据源是在第一个下拉框select的时候load的  
			          url: '/pages/getSelectData.jsp?cpid=1'  
			      }),
			      fields: [
				            { name: 'farmUserRankId' },
				            { name: 'rankName' }
				        ],
			      reader: new Ext.data.JsonReader({
			    		 root: 'data',
	                     successProperty :'success'}
			      )
            }),
            name: 'game_dl',
            displayField: "rankName",  
            valueField :"farmUserRankId",  
            mode : 'remote',  
            forceSelection : true,  
            editable : false,  
            fieldLabel: '请选择代理'
           
        },
        {
        	 xtype: 'textfield',
            name: 'game_area',
            fieldLabel: '请输入大区',
            allowBlank: false,
        },
        {
            xtype: 'textfield',
            name:'game_user',
            fieldLabel: '请输入账号',
            maxLength:30,
            allowBlank: false
        },
        {
            xtype: 'textfield',
            name:'game_password',
            inputType : 'password',  
            fieldLabel: '请输入密码',
            maxLength:30,
            allowBlank: false
        },
        {
            xtype: 'textfield',
            name:'game_nick_name',
            fieldLabel: '请输入角色名',
            allowBlank: false
        }],
        buttons: [
        {
            text: '确定添加',
        	handler:function ()
        	{
        		
    			var sForm = Ext.getCmp("adduseraccount").getForm(); 
    			if(!sForm.isValid())
    			{
    				Ext.Msg.alert('校验失败','请输入合法的数据');    
    				return;
    			}
    			sForm.doAction('submit',{
    				clientValidation:false,
	                url:'http://localhost:8080/pages/addUser.jsp',
	                method:'post', 
                    waitTitle:"请稍候",  
                    waitMsg:"正在提交表单数据，请稍候。。。。。。",  
                    success:function(form,action)
                    {  
                        var isSuccess = action.result.success;   
                        if(isSuccess)
                        {  
                            Ext.Msg.alert('操作成功','操作成功');
                            
                        }else
                        {
                        	 Ext.Msg.alert('操作失败',action.result.code);               
                        }
                            
                              
                    },  
                    failure:function(form, action)
                    {  
                    	if(action.result.code == 302)
                		{
                    		Ext.Msg.confirm('您尚未登录','请重新登录',function(){self.location='/js/login.html'});  
                    		
                		}else
                		{
                			Ext.Msg.alert('操作失败',action.result.code);  
                		}
                    }  
    			});
        	}
        }]
    }]
});
